rm(list = ls())

library(foreign)
library(MASS)
library(AER)
library(splines)
library(mgcv)
library(boot)
library(rgl)
library(margins)
library(lme4)
library(survival)
library(coxme)
library(countrycode)
library(spatialreg)
library(readstata13)
library(sp);library(spdep);library(foreign);library(plm);library(maptools);library(splm);library(texreg)

setwd("~/Dropbox/Systemic Uncertainty/Paper Drafts/International Organization/Final Draft/Final Replication Files/Appendix Replication/")


Data<-read.dta("data_w_allmeasures_int.dta")


Data<-Data[!is.na(Data$longitude),]

Data2<-Data[!is.na(Data$weighted_hege00),]


coords<-coordinates(Data[,c("longitude","latitude")])
W_dist<-dnearneigh(coords,0,1,longlat = F)


datlistw<-nb2listw(W_dist,style="W",zero.policy=T)



coords2<-coordinates(Data2[,c("longitude","latitude")])
W_dist2<-dnearneigh(coords2,0,1,longlat = F)


datlistw2<-nb2listw(W_dist2,style="W",zero.policy=T)


Data3<-Data[!is.na(Data$dw_pca),]


coords3<-coordinates(Data3[,c("longitude","latitude")])
W_dist3<-dnearneigh(coords3,0,1,longlat = F)


datlistw3<-nb2listw(W_dist3,style="W",zero.policy=T)










ft1<-spautolm(make_claim_onset_f ~ hegevolatility00+shape_area_10+rivers+ruggedness,data=Data,listw=datlistw,family="SAR")

summary(ft1)

ft2<-spautolm(make_claim_onset_f ~ weighted_hege00+shape_area_10+rivers+ruggedness,data=Data2,listw=datlistw2,family="SAR")

summary(ft2)

ft3<-spautolm(make_claim_onset_f ~ pca_1+shape_area_10+rivers+ruggedness,data=Data,listw=datlistw,family="SAR")

summary(ft3)

ft4<-spautolm(make_claim_onset_f ~ dw_pca+shape_area_10+rivers+ruggedness,data=Data3,listw=datlistw3,family="SAR")

summary(ft4)

